import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:xv_flutter/app.dart';
import 'package:xv_flutter/model/news.dart' as news;
import 'package:xv_flutter/model/product.dart';
import 'package:xv_flutter/pages/about_us_page.dart';
import 'package:xv_flutter/pages/news_detail_page.dart';
import 'package:xv_flutter/pages/product_detail.dart';

// app路由拦截
Handler appHandler =
    Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return App();
});

// 商品详情路由拦截
Handler detailsHandler =
    Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  String goodsId = params["id"].first;
  print("商品ID ===> $goodsId");

  Items item = Items();
  item.name = "标题";
  item.desc = "具体描述";
  item.imageUrl = "assets/images/products/1.jpeg";
  return ProductDetailPage(item: item);
});

// 新闻详情
Handler newsDetailsHandler =
    Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  String newsId = params["id"].first;
  print("新闻详情ID ===> $newsId");

  news.Items item = news.Items();
  item.title = "标题";
  item.content = "具体内容";
  return NewsDetailPage(item: item);
});

// 联系我们详情
Handler contactHandler =
    Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return AboutContactPage();
});

// webview路由拦截
Handler webHandler =
    Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
  return WebviewScaffold(
      url: "https://www.baidu.com",
      appBar: AppBar(
        title: Text('公司介绍'),
        leading: IconButton(
          icon: Icon(Icons.home),
          onPressed: () {
            // 路由到主界面
            Navigator.of(context).pushReplacementNamed('app');
          },
        ),
      ));
});
